import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import reducer from './reducers';
import rootSaga from './sagas';

const sagaMiddleware = createSagaMiddleware();
let enhancer = applyMiddleware(sagaMiddleware);

if (process.env.NODE_ENV === 'development') {
  const devtools = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
  if (devtools) {
    enhancer = devtools(enhancer);
  }
}
export default initalState => {
  const store = createStore(reducer, initalState, enhancer);
  sagaMiddleware.run(rootSaga);
  return store;
};
